#!/bin/sh
main()
{
. $DOCUMENT_ROOT/apps/home/header.tpl.sh
header_html
cat <<'EOF'
<script>
$(function(){
  $('#post_save_system_setting').on('submit', function(e){
    e.preventDefault();
    var data = "app=system&"+$(this).serialize();
    var url = 'index.cgi';
    Ha.common.ajax(url, 'json', data, 'post', 'post_save_system_setting');
  });
});
</script>
EOF
Time_zone=$(uci get system.@system[0].timezone)
enable_server=$(uci get system.ntp.enable_server)
cat <<EOF
		<div class="pure-g">
			<div class="l-box-lrg pure-u-1 pure-u-md-1-2">
				<h3>系统修改</h3>
EOF
$DOCUMENT_ROOT/apps/system/system.sbin system_status
cat <<EOF
			</div>
			<div class="l-box-lrg pure-u-1 pure-u-md-1-2">
				<h3>固件版本信息</h3>
				固件版本号 :$Firmware_version <br/>
				固件发行时间: $Firmware_release_date<br/>
				更新版本号 :$Updates_version <br/>
				更新发行时间: $Updates_release_date<br/>
				<h3>系统时间设置</h3>
				<form id="post_save_system_setting" class="pure-form">		
					<div class="pure-control-group">
						<label>时区</label>
						<select name="timezone">
						<option value="UTC" `[ "$Time_zone" = "UTC" ] && echo selected`>(UTC) 世界标准时间</option>
						<option value="GMT" `[ "$Time_zone" = "GMT" ] && echo selected`>(GMT)伦敦,都柏林,爱丁堡,冰岛,爱尔兰,里斯本,摩洛哥</option>
						<option value="GMT-1" `[ "$Time_zone" = "GMT-1" ] && echo selected`>(GMT+1)阿姆斯特丹,柏林,马德里,布拉格,巴黎,罗马,维也纳,华沙</option>
						<option value="GMT-2" `[ "$Time_zone" = "GMT-2" ] && echo selected`>(GMT+2)雅典,开罗,开普敦,芬兰,希腊,赫尔辛基,伊斯坦布尔</option>
						<option value="GMT-3" `[ "$Time_zone" = "GMT-3" ] && echo selected`>(GMT+3)安卡拉,阿曼,巴林,科威特,莫斯科,德黑兰,巴格达</option>
						<option value="GMT-4" `[ "$Time_zone" = "GMT-4" ] && echo selected`>(GMT+4)阿布扎比,巴库,喀布尔,喀山,马斯喀特,德黑兰,第比利斯</option>
						<option value="GMT-5" `[ "$Time_zone" = "GMT-5" ] && echo selected`>(GMT+5)加尔各答,科伦坡,伊斯兰堡,马德拉斯,新德里</option>
						<option value="GMT-6" `[ "$Time_zone" = "GMT-6" ] && echo selected`>(GMT+6)阿拉木图,达喀尔,加德满都,科伦坡,斯里兰卡</option>
						<option value="GMT-7" `[ "$Time_zone" = "GMT-7" ] && echo selected`>(GMT+7)曼谷,河内,雅加达,金边,澳大利亚西部标准时间</option>
						<option value="GMT-8" `[ "$Time_zone" = "GMT-8" ] && echo selected`>(GMT+8)北京,重庆,香港,吉隆坡,珀斯,新加坡,台北,乌鲁木齐</option>
						<option value="GMT-9" `[ "$Time_zone" = "GMT-9" ] && echo selected`>(GMT+9)大阪,首尔,札幌,首尔,东京,雅库茨克,达尔文</option>
						<option value="GMT-10" `[ "$Time_zone" = "GMT-10" ] && echo selected`>(GMT+10)布里斯班,堪培拉,关岛,墨尔本,悉尼,海参崴</option>
						<option value="GMT-11" `[ "$Time_zone" = "GMT-11" ] && echo selected`>(GMT+11)马加丹,新喀里多尼亚,所罗门群岛,萨摩亚</option>
						<option value="GMT-12" `[ "$Time_zone" = "GMT-12" ] && echo selected`>(GMT+12)奥克兰,斐济,马绍尔群岛,萨摩亚,惠灵顿,苏瓦</option>
						<option value="GMT+12" `[ "$Time_zone" = "GMT+12" ] && echo selected`>(GMT-12)埃尼威托克</option>
						<option value="GMT+11" `[ "$Time_zone" = "GMT+11" ] && echo selected`>(GMT-11)中途岛,萨摩亚群岛</option>
						<option value="GMT+10" `[ "$Time_zone" = "GMT+10" ] && echo selected`>(GMT-10)夏威夷,檀香山,夏威夷标准时间</option>
						<option value="GMT+9" `[ "$Time_zone" = "GMT+9" ] && echo selected`>(GMT-9)阿拉斯加,阿拉斯加标准时间</option>
						<option value="GMT+8" `[ "$Time_zone" = "GMT+8" ] && echo selected`>(GMT-8)洛杉矶,圣迭戈,旧金山,西雅图,蒂华纳,温哥华</option>
						<option value="GMT+7" `[ "$Time_zone" = "GMT+7" ] && echo selected`>(GMT-7)丹佛,埃德蒙顿,凤凰城,盐湖城</option>
						<option value="GMT+6" `[ "$Time_zone" = "GMT+6" ] && echo selected`>(GMT-6)芝加哥,达拉斯,危地马拉,休斯顿</option>
						<option value="GMT+5" `[ "$Time_zone" = "GMT+5" ] && echo selected`>(GMT-5)波士顿,纽约,华盛顿</option>
						<option value="GMT+4" `[ "$Time_zone" = "GMT+4" ] && echo selected`>(GMT-4)加拉加斯,拉布拉多,拉巴斯,滨海,圣地亚哥,</option>
						<option value="GMT+3" `[ "$Time_zone" = "GMT+3" ] && echo selected`>(GMT-3)巴西利亚,布宜诺斯艾利斯,乔治敦,里约热内卢</option>
						<option value="GMT+2" `[ "$Time_zone" = "GMT+2" ] && echo selected`>(GMT-2)中大西洋</option>
						<option value="GMT+1" `[ "$Time_zone" = "GMT+1" ] && echo selected`>(GMT-1)亚速尔群岛,佛得角群岛,非洲西部时间</option>
						</select>
					</div>
					<div class="pure-control-group">
						<label class="pure-checkbox">
						<input id="option-one" name="time_server" type="checkbox" value="1" style="position:relative;top:35px;" `[ $enable_server -eq 1 ] && echo checked`>
						开启时间服务器
						</label>

					<div class="pure-control-group">
						<label>时间更新服务器</label>
EOF
for time_server in `uci get system.ntp.server | sed 's/[ ]/\n/g' | head -n 5`
do
[ -n "$num" ] && num=`expr $num + 1` || num=1
cat <<EOF
						<input type="text" name="server${num}" placeholder="Enter NTP TimeServer" value="${time_server}" class="form-control"><br/>
EOF
done
cat <<EOF
					</div>
					<div class="pure-control-group">
						<input type="hidden" name="action" value="post_save_system_setting">
						<button type="submit" class="pure-button">保存</button>
					</div>
				</form>
				</div>
			</div>
		</div>
EOF


footer_html
}
post_save_system_setting()
{
uci set system.@system[0].timezone="$FORM_timezone"
[ -z "$FORM_time_server" ] && FORM_time_server=0
uci set system.ntp.enable_server="$FORM_time_server"
uci delete system.ntp.server
uci add_list system.ntp.server="$FORM_server1"
uci add_list system.ntp.server="$FORM_server2"
uci add_list system.ntp.server="$FORM_server3"
uci add_list system.ntp.server="$FORM_server4"
uci add_list system.ntp.server="$FORM_server5"
uci commit system
echo "时间设置成功!!" | main.sbin output_json 0
}
post_change_hostname()
{
$DOCUMENT_ROOT/apps/$FORM_app/system.sbin do_set_hostname
echo "机器名已修改完成,需要重启!!" | main.sbin output_json 0
}
get_systeminfo()
{
printf "Content-Type: text/html; charset=utf-8\r\n"
printf "\r\n"
$DOCUMENT_ROOT/apps/system/system.bin sysinfo
}
lang=`main.sbin get_client_lang`
eval `cat $DOCUMENT_ROOT/apps/$FORM_app/i18n/$lang/i18n.conf`
eval `grep -E "^Firmware_|^Updates_" $(main.sbin www_root)/apps/system/config.conf`
if
[ $is_main_page = 1 ]
then
main
elif [ -n "$FORM_action" ]
then
$FORM_action
fi
